//
//  AISHTTPServer.m
//  AISUPnP
//
//  Created by Ares on 1/27/15.
//  Copyright (c) 2015 Ares. All rights reserved.
//

#import "AISHTTPServer.h"

AISHTTPServer *gHTTPServer;

@implementation AISHTTPServer

+ (AISHTTPServer *)sharedInstance
{
    if (nil == gHTTPServer)
    {
        gHTTPServer = [[AISHTTPServer alloc] init];
    }
    
    return gHTTPServer;
}

- (id)init
{
    self = [super init];
    if (nil != self)
    {
        [self setType:@"_http._tcp."];
//        NSString *webPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"WebRoot"];
        NSString *webPath = [[NSBundle mainBundle] resourcePath];
        NSLog(@"Setting document root: %@", webPath);
        
        [self setDocumentRoot:webPath];
        [self startServer];
    }
    return self;
}

- (void)startServer
{
    // Start the server (and check for problems)
    NSError *error;
    if([self start:&error])
    {
        NSLog(@"Started HTTP Server on port %hu", [self listeningPort]);
    }
    else
    {
        NSLog(@"Error starting HTTP Server: %@", error);
    }
}

@end
